<?php

/*
	This file is part of Mandragon.

    Mandragon is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Mandragon is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Mandragon.  If not, see <http://www.gnu.org/licenses/>.
*/

require_once 'PHPUnit/Framework.php';
require_once 'autoload.php';

class TestAdminPage extends PHPUnit_Framework_TestCase {
	
	function test_page_inc_check_access() {
		$page = new Page();

		$add_item_page = new AdminPage();
		$mock_access = $this->getMock('AccessManager');
		$mock_access->expects($this->once())
				->method('check_access')
				->with('ADMIN');
		$add_item_page->set_access_manager($mock_access);

		$add_item_page->page_inc_check_access($page);
	}

	function test_page_inc_execute_action() {
		$expected_action = "some action";

		$page = new Page();

		$admin_page = new AdminPage();

		$mock_alerter = $this->getMock('Alerter');
		$mock_alerter->expects($this->once())
				->method('add_alert')
				->with("unknown action: $expected_action");
		$admin_page->set_alerter($mock_alerter);

		$admin_page->page_inc_execute_action($page, $expected_action);
	}

	function test_page_inc_execute() {
		$expected_dir  = array();

		$page = new Page();

		$page->directory_tree[1] = $expected_dir;
		$page->dir_depth = 2;

		$admin_page = new AdminPage();

		$mock_toolbox = $this->getMock('Toolbox');
		$mock_toolbox->expects($this->at(0))
				->method('add_action')
				->with($this->equalto($page, 'add_dir', 'url', '.edit_dir?action=add'));
		$mock_toolbox->expects($this->at(1))
				->method('add_action')
				->with($this->equalto($page, 'user_management', 'url', '.usermgm'));
		$mock_toolbox->expects($this->at(2))
				->method('add_action')
				->with($this->equalto($page, 'access', 'url', '.access'));
		$mock_toolbox->expects($this->at(3))
				->method('add_action')
				->with($this->equalto($page, 'location', 'url', '.location'));
		$mock_toolbox->expects($this->at(4))
				->method('add_action')
				->with($this->equalto($page, 'profiles', 'url', '.profile'));
		$mock_toolbox->expects($this->at(5))
				->method('add_action')
				->with($this->equalto($page, 'maintenance', 'url', '.maintenance'));
		$mock_toolbox->expects($this->at(6))
				->method('add_action')
				->with($this->equalto($page, 'logs', 'url', '.logs'));
		$mock_toolbox->expects($this->at(7))
				->method('add_action')
				->with($this->equalto($page, 'mailcontents', 'url', '.mailcontentmgm'));
		$admin_page->set_toolbox($mock_toolbox);

		$admin_page->page_inc_execute($page);

		$this->assertEquals('Administrator panel', $page->content['title']);
		$this->assertEquals('<p>Selecteer een van bovenstaande acties.</p>', $page->content['body']);
	}

	function test_page_inc_dress() {
		$page = new Page();

		$admin_page = new AdminPage();
		$admin_page->page_inc_dress($page);

		$this->assertTrue($page->content['body_printed']);
	}
}

function print_body($page) {
	$page->content['body_printed'] = true;
}

?>
